package cn.myjerry.io.buffered;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

/**
 * 字节流文件拷贝 + 缓冲流 提高性能
 * @author Jerry
 *
 */
public class BufferedByteDemo {
	public static void main(String[] args) {
		
	}
	public static void copyFile(String srcPath, String destPath) throws IOException {
		File src = new File(srcPath);
		File src1 = new File(destPath);
		if(!src.isFile()) {
			throw new IOException("只能拷贝文件");
		}
		InputStream is = null;
		OutputStream os = null;
		is = new BufferedInputStream(new FileInputStream(src));
		os = new BufferedOutputStream(new FileOutputStream(src1, true));
		byte[] car = new byte[1024];
		int len = 0;
		while(-1 != (len = is.read(car))) {
			os.write(car, 0, len);
			os.flush();
		}
		is.close();
		os.close();
	}
}
